package com.kdtech.analyse.video;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.analyse.AnalyseNews;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.RegexUtils;
import com.kdtech.utils.StringUtils;

/**
 * <新闻 - 齐齐哈尔电视台> 解析类
 *
 * @author KK
 *
 */
public class QqhrgdAnalyse implements AnalyseNews {



	
	public boolean isDetailPage(String url) {


		String[] regex = {
				"http://www.qqhrgd.com/html/[0-9]{4}/[a-z]*_[0-9]{4}/[0-9]*.html",
				};

		return RegexUtils.matchAny(url,regex);
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		if (urlMeta.getHtml() == null) {
		}
		String htmltxt = urlMeta.getHtml();
		String url = urlMeta.getUrl();

		String title = null;
		String desc = null;
		Long date = null;
		String dateStr = null;
		String commnetNum = null;
		String clickNum = null;
		String updateUrl = null;
		Document doc = Jsoup.parse(htmltxt);

		title =   doc.select("div#Article h1").text();
		dateStr = doc.select("div#Article h1 ").text();
		commnetNum = doc.select("div#Article h1 span a#comment").text();
		clickNum = doc.select("div#Article h1 span#hits").text();
		desc=doc.select("div#Article div.summary").text();
		if(StringUtils.isNotBlank(title)){
			 title = StringUtils.substringBefore(title, " ");
		}
		date = DateUtils.matchDate(dateStr);
		 desc = HtmlCleaner.getContentHtml(url, doc.select("div.content"));
			NewsMeta news = new NewsMeta();
			news.setUrl(url);
			news.setType(2);
			news.setTitle(StringUtils.trimSpace(title));
			news.setCommentNum(NumberUtils.parseInt(commnetNum));
			news.setClickNum(NumberUtils.parseInt(clickNum));
			news.setDate(date);
			news.setContent(desc);
			if (StringUtils.isNotBlank(updateUrl)){
				news.setUpdateUrl(updateUrl);
				Update(news);
			}
			return news;

	}

	

	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}


	
}
